package ldh.im.fxbase.data.pojo;

import ldh.im.fxbase.cache.SoftId;
import ldh.im.fxbase.data.pojo.status.ImGroupStatus;
import ldh.im.fxbase.data.pojo.status.ImGroupType;
import ldh.im.fxbase.util.StringUtil;

import java.util.Date;
import java.util.Set;

public class ImGroup implements SoftId {

    private Long id;
    private String currentUserId;
    private String code;
    private String serverId;
    private String name;
    private String ownerId;   // 群主
    private String description;
    private Long version;
    private ImGroupType groupType;
    private ImGroupStatus status;
    private String ext1;
    private String ext2;
    private String firstLetter;
    private Date createTime;
    private Date updateTime;

    private transient boolean isTop;
    private transient String userName;
    private transient ImUser imUser;

    private Set<ImGroupUser> groupUserSet;
    private transient ImGroupUser currentGroupUser;
    private transient String sessionId;

    public ImGroup() {
        createTime = new Date();
        updateTime = new Date();
        status = ImGroupStatus.enable;
        version = 0L;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getServerId() {
        return serverId;
    }

    public void setServerId(String serverId) {
        this.serverId = serverId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
        this.firstLetter = StringUtil.firstLetter(name);
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Long getVersion() {
        if (version == null) version = 0L;
        return version;
    }

    public void setVersion(Long version) {
        this.version = version;
    }

    public boolean isTop() {
        return isTop;
    }

    public void setTop(boolean top) {
        isTop = top;
    }

    @Override
    public String getSoftId() {
        return id+"";
    }

    public Set<ImGroupUser> getGroupUserSet() {
        return groupUserSet;
    }

    public void setGroupUserSet(Set<ImGroupUser> groupUserSet) {
        this.groupUserSet = groupUserSet;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getOwnerId() {
        return ownerId;
    }

    public void setOwnerId(String ownerId) {
        this.ownerId = ownerId;
    }

    public ImGroupStatus getStatus() {
        return status;
    }

    public void setStatus(ImGroupStatus status) {
        this.status = status;
    }

    public ImUser getImUser() {
        return imUser;
    }

    public void setImUser(ImUser imUser) {
        this.imUser = imUser;
    }

    public String getCurrentUserId() {
        return currentUserId;
    }

    public void setCurrentUserId(String currentUserId) {
        this.currentUserId = currentUserId;
    }

    public ImGroupType getGroupType() {
        return groupType;
    }

    public void setGroupType(ImGroupType groupType) {
        this.groupType = groupType;
    }

    public String getExt1() {
        return ext1;
    }

    public void setExt1(String ext1) {
        this.ext1 = ext1;
    }

    public String getExt2() {
        return ext2;
    }

    public void setExt2(String ext2) {
        this.ext2 = ext2;
    }

    public String getFirstLetter() {
        return firstLetter;
    }

    public void setFirstLetter(String firstLetter) {
        this.firstLetter = firstLetter;
    }

    public ImGroupUser getCurrentGroupUser() {
        return currentGroupUser;
    }

    public void setCurrentGroupUser(ImGroupUser currentGroupUser) {
        this.currentGroupUser = currentGroupUser;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof ImGroup)) return false;
        ImGroup imGroup = (ImGroup) obj;
        if (imGroup.getCode() != null && this.getCode() != null) {
            return imGroup.getCode().equals(this.getCode());
        }
        if (imGroup.getServerId() != null && this.getServerId() != null) {
            return imGroup.getServerId().equals(this.getServerId());
        }
        return imGroup.getId().equals(this.getId());
    }

    @Override
    public int hashCode() {
        return this.getCode().hashCode();
    }
}
